package com.xing.controller;


import com.xing.common.lang.Result;
import com.xing.model.User;
import com.xing.service.UserService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  用户管理控制器
 * </p>
 *
 * @author 柠檬有点甜
 * @since 2021-08-17
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;


    @GetMapping("/{id}")
    public Object userbyid(@PathVariable("id") long id){
        User user = userService.getById(id);
        return Result.succ(user);
    }
/*可以做数据缓存*/
    @GetMapping("/love/{id}")
    public Result updateLove(@PathVariable("id") long id){
        User user = userService.getById(id);
        user.setLove(user.getLove()+1);
//        点赞修改功能每调用一次点赞一次
        userService.updateById(user);
        return Result.succ(null);
    }


    //经过认证才能访问 测试
    @RequiresAuthentication
    @GetMapping("/index")
    public Object test(){
        User user = userService.getById(1L);
        return Result.succ(user);
    }
}

